﻿using Common.Builders.Interfaces;
using Common.Entities;
using Common.ServiceResponse;

namespace Common.Builders
{
    public class UserBuilder : IUserBuilder
    {
        private string _userName;
        private string _password;
        private UserAccounts _userAccounts;
        private Sessions _history;
        private Preferences _preferences;
        private SecurityKey _securityKey;
        private ResponseDetails _responseDetails;

        public User Build()
        {
            return new User(_userName, _password, _userAccounts, _history, _preferences, _securityKey, _responseDetails);
        }

        public IUserBuilder WithUserName(string userName)
        {
            _userName = userName;
            return this;
        }

        public IUserBuilder WithPassword(string password)
        {
            _password = password;
            return this;
        }

        public IUserBuilder WithUserAccounts(UserAccounts userAccounts)
        {
            _userAccounts = userAccounts;
            return this;
        }

        public IUserBuilder WithSecurityKey(SecurityKey securityKey)
        {
            _securityKey = securityKey;
            return this;
        }

        public IUserBuilder WithResponseDetails(ResponseDetails responseDetails)
        {
            _responseDetails = responseDetails;
            return this;
        }

        public IUserBuilder FromUser(User user)
        {
            _userName = user.UserName;
            _password = user.Password;
            _userAccounts = user.UserAccounts;
            _history = user.History;
            _preferences = user.Preferences;
            _securityKey = user.SecurityKey;
            _responseDetails = user.ResponseDetails;
            return this;
        }

        public void ClearAll()
        {
            _userName = string.Empty;
            _password = string.Empty;
            _userAccounts = null;
            _history = null;
            _preferences = null;
            _securityKey = null;
            _responseDetails = null;
        }

    }
}
